#include "UdpServer.hpp"
#include "User.hpp"

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " serverport" << std::endl;
        exit(USAGE_ERROR);
    }
    
    uint16_t serverport = std::stoi(argv[1]);

    ENABLE_CONSOLE_LOG();

	// 用户管理
    std::shared_ptr<UserManage> um = std::make_shared<UserManage>();
    std::unique_ptr<UdpServer> udp = std::make_unique<UdpServer>(serverport);
    udp->RegisterService([&um](const InetAddr& id){
        um->AddUser(id); }, 
                        [&um](int sockfd, const std::string &message){
        um->Router(sockfd, message); }
        );

    udp->InitUdpServer();
    udp->Start();

    return 0;
}
